#include "R_Geometrist.h"
#include "Geometrist_Wrap.h"
#include "R_Geometry_S4.h"

namespace RSuperMap
{
	RcppExport SEXP R_Geometrist_create_buffer(SEXP pointer, SEXP dists, SEXP side, SEXP segments, SEXP endType, SEXP unit, SEXP prj)
	{
		BEGIN_RCPP
			SEXP __result;
		UGC::UGGeometry* pGeometry = (UGC::UGGeometry*) EXTPTR_PTR(pointer);
		Rcpp::NumericVector radius(dists);
		std::string strSide = RTools::as_str(side);
		UGint nSegment = Rcpp::as<UGint>(segments);
		std::string strEnd = RTools::as_str(endType);
		std::string strUnit = RTools::as_str(unit);

		UGdouble dLeft(0.0), dRight(0.0);
		if(radius.size() == 2)
		{
			dLeft = radius[0];
			dRight = radius[1];
		}
		else if(radius.size() == 1)
		{
			dLeft = radius[0];
			dRight = radius[0];
		}
		else
		{
			__result = Rcpp::wrap<bool>(false);
			return __result;
		}

		UGGeoRegion* pGeoRes = Geometrist_wrap_create_buffer(pGeometry, dLeft, dRight,
			strSide.c_str(), strEnd.c_str(), strUnit.c_str(), nSegment, NULL);
		if(pGeoRes != NULL)
		{
			__result = Rcpp::wrap(S4_GeoRegion(pGeoRes));
		}
		else
		{
			__result = Rcpp::wrap<bool>(false);
		}
		return __result;
		END_RCPP
	}
}